<?php

/**
 * @package Bike
 * @subpackage Storage
 */

/**
 * Storages interface
 * @author Chrome
 * @package Bike
 * @subpackage Storage
 */
interface Bike_Storage_IBase {
	
	/**
	 * Constructor
	 * @param array $fields storage fields
	 */
	public function __construct(array $fields);
	
	/**
	 * Get fields from storage
	 * @return array
	 */
	public function getFields();
	
	/**
	 * Set readable connection to storage
	 * @param Bike_Db_Idb $connection
	 * @return boolean
	 */
	public function setReadableConnection(Bike_Db_Idb $connection);
	
	/**
	 * Get previously stored readable connection
	 * @return Bike_Db_Idb
	 */
	public function getReadableConnection();
	
	/**
	 * Set writable connection to storage
	 * @param Bike_Db_Idb $connection
	 * @return boolean
	 */
	public function setWritableConnection(Bike_Db_Idb $connection);
	
	/**
	 * Get previously stored writable connection
	 * @return Bike_Db_Idb
	 */
	public function getWritableConnection();
	
	/**
	 * Set storage name
	 * @param string $storageName
	 * @return boolean
	 */
	public function setStorageName($storageName);
	
	/**
	 * Get records by conditions
	 * @param array $filters
	 * @param int $offset
	 * @param int $limit
	 * @param array $sortings 'field' => 'direction'
	 */
	public function getRecordsByConditions(array $filters, $offset = 0, $limit = 20, array $sortings = array());
	
	/**
	 * Update record by $id with $data
	 * @param int $id
	 * @param array $data
	 * @return boolean
	 */
	public function updateRecord($id, array $data);
	
	/**
	 * Insert record with $data
	 * @param array $data
	 * @return boolean
	 */
	public function insertRecord(array $data);
	
	/**
	 * Delete record with #id
	 * @param int $id
	 * @return boolean
	 */
	public function deleteRecord($id);
}
